package 面向对象.day05;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

/**
 * @author 王敬仟
 * SeaObjeck 海洋对象抽象类
 */
public abstract class SeaObject {
    /*设置游戏状态*/
    public static final int LIVE=0;//活着的
    public static final int DEAD=1;//死了的
    protected int state=LIVE;//设置游戏当前状态为活着的
    /*海洋对象的共有属性*/
    protected int width;//宽
    protected int height;//高
    protected int x;//x轴坐标
    protected int y;//y轴坐标
    protected int speed;//移动速度
    /*给共有属性赋值 潜艇对象*/
    public SeaObject(int width,int height){
        this.width = width;
        this.height = height;
        x = -width;
        Random rand = new Random();
        y = rand.nextInt(479-height-150+1)+150;
        speed = rand.nextInt(3)+1;
    }
    /*重写海洋对象方法 给炸弹 鱼雷赋值*/
    public SeaObject(int width,int height,int x,int y,int speed){
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }
    /*海洋对象的移动方法 设置成抽象类*/
    public abstract void move();
    /*设置图片抽象类*/
    public abstract ImageIcon getImage();
    /*判断当前对象是否是活着的*/
    public boolean isLive(){
        return state==LIVE;
    }
    /*判读当前对象是否是死了的*/
    public boolean isDead(){
        return state==DEAD;
    }
    /*画对象*/
    public void paintImage(Graphics g){
        //判断如果是活着的
        if(isLive()){
            //画对象
            this.getImage().paintIcon(null,g,x,y);
        }
    }
    /** 检测潜艇越界 */
    public boolean isOutOfBounds(){
        //x>=窗口宽，即为越界了
        return x>= World.WIDTH;
    }
}
